module.exports = function($scope, $state, $stateParams, $modalInstance, items, $resource){
   

    $scope.item=items;
    console.log($scope.item);
    console.log('上面是item');
    $scope.obj={};
    $scope.arr = [];
    $scope.product_type6=[];
    $scope.product_type5=items.product_type.split(',');
    console.log($scope.product_type5);
    console.log('上面是切割完的$scope.product_type5')
    if($scope.product_type5[0]==''){
        $scope.product_type5=[];
    }
    $scope.employee = {};
    $scope.ptarr=[];
    $scope.ptarr.push({name:$scope.product_type});   
    $scope.ptarr2=[];
    $scope.showinfo = {
				'product_type' : [
					{'name' : '周边游', 'value' : '0'},
	                {'name' : '国内长线', 'value' : '1'},
	                {'name' : '国内当地参团', 'value' : '2'},
	                {'name' : '出境当地参团', 'value' : '3'},
	                {'name' : '出境短线', 'value' : '4'},
                    {'name' : '出境长线', 'value' : '5'},
	            ],
            }
 


 //正则判断电话号
            $scope.checkphone=function(x){
                if(!/^1[34578]\d{9}$/.test(x)) return "您输入的电话号长度或格式错误";
            }
            $scope.showphoneinfo=function(x){
                console.log(x);
                if(x==undefined){
                    $scope.employee.phoneinfo="";
                   return;
                  }
                if(x==''){
                    $scope.employee.phoneinfo="";
                   return;
                  }
                                         
            if($scope.checkphone(x)=="您输入的电话号长度或格式错误"){                
                $scope.employee.phoneinfo="您输入的电话号长度或格式错误"
            }else{
                     $scope.employee.phoneinfo="";
                    }
            }
    

       
    $scope.cancel = function () {
    if($scope.item.product_type_name=='0'){
        $scope.item.product_type_name='周边游'
    };
    if($scope.item.product_type_name=='1'){
        $scope.item.product_type_name='国内长线'
    };
    if($scope.item.product_type_name=='2'){
        $scope.item.product_type_name='国内当地参团'
    };
    if($scope.item.product_type_name=='3'){
        $scope.item.product_type_name='出境当地参团'
    };
    if($scope.item.product_type_name=='4'){
        $scope.item.product_type_name='出境短线'
    };
    if($scope.item.product_type_name=='5'){
        $scope.item.product_type_name='出境长线'
    };  
        $modalInstance.dismiss('cancel'); 
    };

    $scope.addemployee = function(){
        $scope.lcshow = 0;
                    if($scope.product_type1==undefined){
                        return;
                    }                  
                    if($scope.product_type1=='0'){
                       $scope.product_type1='周边游'
                    };
                    if($scope.product_type1=='1'){
                        $scope.product_type1='国内长线'
                    };
                    if($scope.product_type1=='2'){
                        $scope.product_type1='国内当地参团'
                    };
                    if($scope.product_type1=='3'){
                        $scope.product_type1='出境当地参团'
                    };
                    if($scope.product_type1=='4'){
                        $scope.product_type1='出境短线'
                    };
                    if($scope.product_type1=='5'){
                        $scope.product_type1='出境长线'
                    };  
                 for(var i = 0;i<$scope.product_type5.length;i++){
                    if($scope.product_type1==$scope.product_type5[i]){
                        alert('不能重复添加');
                        return;
                    }
                }       
				$scope.product_type6=[];   
                $scope.product_type5.push($scope.product_type1);
                
                for(var i = 0;i<$scope.product_type5.length;i++){
                    $scope.product_type6.push($scope.product_type5[i]);
                }
                 console.log($scope.product_type6);
							

				

			};
        $scope.remove = function(index){
                console.log($scope.product_type5);             
                $scope.product_type5.splice(index,1);
                if($scope.product_type5.length==0){
                    $scope.lcshow = 1;
                }else{
                     $scope.lcshow = 0;
                }
    
            
            $scope.product_type6=[];

            console.log($scope.product_type5);
            for(var i = 0;i<$scope.product_type5.length;i++){
                    $scope.product_type6.push($scope.product_type5[i]);
                }
            
        }  
    $scope.gogogo = function () {              
        for(var i = 0;i<$scope.product_type6.length;i++){

                    if($scope.product_type6[i]=="周边游"){
                        $scope.product_type6[i]="0"
                    }
                    if($scope.product_type6[i]=='国内长线'){
                        $scope.product_type6[i]='1'
                    };
                    if($scope.product_type6[i]=='国内当地参团'){
                        $scope.product_type6[i]='2'
                    };
                    if($scope.product_type6[i]=='出境当地参团'){
                        $scope.product_type6[i]='3'
                    };
                    if($scope.product_type6[i]=='出境短线'){
                        $scope.product_type6[i]='4'
                    };
                    if($scope.product_type6[i]=='出境长线'){
                        $scope.product_type6[i]='5'
                    };
        }
        // console.log($scope.product_type5);
       $scope.stptarr2='';
        for(var i = 0;i<$scope.product_type6.length;i++){
            if(i<$scope.product_type6.length-1){
                $scope.stptarr2+=$scope.product_type6[i]+',';
            }else{
                $scope.stptarr2+=$scope.product_type6[i];
            }
        }
        

        $scope.obj['name']=$scope.item.name;
        $scope.obj['mobile']=$scope.item.mobile;
        $scope.obj['product_type']=$scope.stptarr2;
        $scope.obj['id']=$scope.item.id;
        console.log($scope.obj);
        console.log('上面是scope.obj')
        
        if($scope.item.name==undefined){
            alert('请输入联系人姓名');
            return;
        }
        if($scope.item.mobile==undefined){
            alert('请输入联系人电话号码');
            return;
        }
        if($scope.employee.phoneinfo!=''&&$scope.employee.phoneinfo!=undefined){
            alert('请输入正确的电话号码！');
            console.log($scope.employee.phoneinfo);
            return;
        }
        
        $resource('/api/as/lc/employee/updateById', {}, {}).save($scope.obj, function(res){
            // console.log(res);
            if(res.errcode === 0){
                $modalInstance.close($scope.result);
                alert('保存成功');
            }else{
                alert(res.errmsg);
            }
        });
    };
};